package person

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/person"
    personReq "github.com/flipped-aurora/gin-vue-admin/server/model/person/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type CasPersonsApi struct {}



// CreateCasPersons 创建casPersons表
// @Tags CasPersons
// @Summary 创建casPersons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body person.CasPersons true "创建casPersons表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /casPersons/createCasPersons [post]
func (casPersonsApi *CasPersonsApi) CreateCasPersons(c *gin.Context) {
	var casPersons person.CasPersons
	err := c.ShouldBindJSON(&casPersons)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casPersonsService.CreateCasPersons(&casPersons)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteCasPersons 删除casPersons表
// @Tags CasPersons
// @Summary 删除casPersons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body person.CasPersons true "删除casPersons表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /casPersons/deleteCasPersons [delete]
func (casPersonsApi *CasPersonsApi) DeleteCasPersons(c *gin.Context) {
	ID := c.Query("ID")
	err := casPersonsService.DeleteCasPersons(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteCasPersonsByIds 批量删除casPersons表
// @Tags CasPersons
// @Summary 批量删除casPersons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /casPersons/deleteCasPersonsByIds [delete]
func (casPersonsApi *CasPersonsApi) DeleteCasPersonsByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := casPersonsService.DeleteCasPersonsByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateCasPersons 更新casPersons表
// @Tags CasPersons
// @Summary 更新casPersons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body person.CasPersons true "更新casPersons表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /casPersons/updateCasPersons [put]
func (casPersonsApi *CasPersonsApi) UpdateCasPersons(c *gin.Context) {
	var casPersons person.CasPersons
	err := c.ShouldBindJSON(&casPersons)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casPersonsService.UpdateCasPersons(casPersons)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindCasPersons 用id查询casPersons表
// @Tags CasPersons
// @Summary 用id查询casPersons表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query person.CasPersons true "用id查询casPersons表"
// @Success 200 {object} response.Response{data=person.CasPersons,msg=string} "查询成功"
// @Router /casPersons/findCasPersons [get]
func (casPersonsApi *CasPersonsApi) FindCasPersons(c *gin.Context) {
	ID := c.Query("ID")
	recasPersons, err := casPersonsService.GetCasPersons(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(recasPersons, c)
}
// GetCasPersonsList 分页获取casPersons表列表
// @Tags CasPersons
// @Summary 分页获取casPersons表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query personReq.CasPersonsSearch true "分页获取casPersons表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /casPersons/getCasPersonsList [get]
func (casPersonsApi *CasPersonsApi) GetCasPersonsList(c *gin.Context) {
	var pageInfo personReq.CasPersonsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := casPersonsService.GetCasPersonsInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}
// GetCasPersonsDataSource 获取CasPersons的数据源
// @Tags CasPersons
// @Summary 获取CasPersons的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /casPersons/getCasPersonsDataSource [get]
func (casPersonsApi *CasPersonsApi) GetCasPersonsDataSource(c *gin.Context) {
    // 此接口为获取数据源定义的数据
    dataSource, err := casPersonsService.GetCasPersonsDataSource()
    if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
   		response.FailWithMessage("查询失败:" + err.Error(), c)
   		return
    }
   response.OkWithData(dataSource, c)
}

// GetCasPersonsPublic 不需要鉴权的casPersons表接口
// @Tags CasPersons
// @Summary 不需要鉴权的casPersons表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /casPersons/getCasPersonsPublic [get]
func (casPersonsApi *CasPersonsApi) GetCasPersonsPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    casPersonsService.GetCasPersonsPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的casPersons表接口信息",
    }, "获取成功", c)
}
